<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="/layout/template.xhtml">

<ui:define name="body">

    <h:form id="categoria" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{categoriaHome.managed ? 'Editar' : 'Cadastro de'} Categoria</f:facet>

			<s:div styleClass="tableControl" rendered="#{empty from}">
        		<s:link view="/resources/CategoriaList.xhtml"
		                    id="list"
		           propagation="none">
		            <h:graphicImage url="/img/list.png"/>
		            #{' '}
		            <h:outputLabel value="Listagem"/>
		        </s:link>
		    </s:div>

            <s:decorate id="nomeField" template="/layout/edit.xhtml">
                <ui:define name="label">Nome</ui:define>
                <h:inputTextarea id="nome"
                               cols="80"
                               rows="3"
                              value="#{categoriaHome.instance.nome}"
                           required="true"/>
            </s:decorate>
            
            
            <s:decorate id="descricaoField" template="/layout/edit.xhtml">
                <ui:define name="label">Descrição</ui:define>
                <h:inputTextarea id="descricao"
                               cols="80"
                               rows="3"
                              value="#{categoriaHome.instance.descricao}"/>
            </s:decorate>


            <div style="clear:both">
                <span class="required">*</span>
                campos obrigatórios
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Salvar"
                         action="#{categoriaHome.persist}"
                       disabled="#{!categoriaHome.wired}"
                       rendered="#{!categoriaHome.managed}"/>

            <h:commandButton id="update"
                          value="Salvar"
                         action="#{categoriaHome.update}"
                       rendered="#{categoriaHome.managed}"/>

            <h:commandButton id="delete"
                          value="Deletar"
                         action="#{categoriaHome.remove}"
                      immediate="true"
                       rendered="#{categoriaHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancelar"
             propagation="end"
                    view="/resources/Categoria.xhtml"
                rendered="#{categoriaHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancelar"
             propagation="end"
                    view="/resources/#{empty categoriaFrom ? 'CategoriaList' : categoriaFrom}.xhtml"
                rendered="#{!categoriaHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="Usuário">
    <div class="association" id="usuarioParent">

        <h:outputText value="Não existe usuário associado a esta Categoria."
                   rendered="#{categoriaHome.instance.usuario == null}"/>

        <rich:dataTable var="_usuario"
                   value="#{categoriaHome.instance.usuario}"
                rendered="#{categoriaHome.instance.usuario != null}"
              rowClasses="odd,even"
                      id="usuarioTable">
            <h:column>
                <f:facet name="header">Nome</f:facet>
                <h:outputText value="#{_usuario.nome}"/>
            </h:column>
            <h:column>
                <f:facet name="header">E-mail</f:facet>
                <h:outputText value="#{_usuario.email}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Data de Cadastro</f:facet>
                <h:outputText value="#{_usuario.dataCadastro.time}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Status</f:facet>
                <h:outputText value="#{_usuario.status}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{categoriaHome.instance.usuario != null ? 'changeParent' : 'selectParent'}" value="#{categoriaHome.instance.usuario != null ? 'Trocar' : 'Selecionar'} Usuário"
                       view="/resources/UsuarioList.xhtml"
                       rendered="#{s:hasRole('Subgrupo')}">
                <f:param name="from" value="CategoriaEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
